package com.deer.wms.kuaidiniao.service.impl;

import com.alibaba.fastjson.JSONArray;
import com.deer.wms.kuaidiniao.constant.KuaidiniaoConstant;
import com.deer.wms.kuaidiniao.model.EOrderRequestData;
import com.deer.wms.kuaidiniao.model.EOrderRequestData;
import com.deer.wms.kuaidiniao.utils.Utils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

@Service
@Transactional
public class EOrderApi {
    /**
     * 电子面单 对象方式
     */
    String orderOnlineByRequestData(EOrderRequestData requestData) throws Exception {
        String jsonData = "";
        jsonData = JSONArray.toJSONString(requestData);
        return orderOnlineByJson(jsonData);
    }

    /**
     * Json方式 电子面单
     * @throws Exception
     */
    private String orderOnlineByJson(String requestData) throws Exception{

        Map<String, String> params = new HashMap<String, String>();
        params.put("RequestData", Utils.urlEncoder(requestData, "UTF-8"));
        params.put("EBusinessID", KuaidiniaoConstant.EBusinessID);
        params.put("RequestType", "1007");
        String dataSign = Utils.encrypt(requestData, KuaidiniaoConstant.AppKey, "UTF-8");
        params.put("DataSign", Utils.urlEncoder(dataSign, "UTF-8"));
        params.put("DataType", "2");

        String result=Utils.sendPost(KuaidiniaoConstant.DzmdReqURL, params);

        return result;
    }
}
